package 素数筛选.计数质数;

import java.util.Arrays;

/**
 * TODO
 *
 * @className: jszs
 * @description: TODO
 * @author: 等什么柠檬君
 * @date: 2022-05-06 19:39
 **/
public class jszs2 {
    public static void main(String[] args) {
        System.out.println(countPrimes(2));
    }

    /**
     * 很不幸 超时
     * @param n
     * @return
     */
    public static int countPrimes(int n) {
        if( n <= 1){
            return 0;
        }
        int count = 0;
        for (int i = 2; i < n; i++) {
            if (isPrimay(i)){
                System.out.println("是质数");
                ++count;
            }
        }
        return count;
    }
    public static boolean isPrimay(int n){
        if ((n & 1)==0 && n > 2 ){
            return false;
        }
        for (int i = 2; i <= Math.sqrt(n); i++) {
            if (i != n && n % i == 0){
                return false;
            }
        }
        return true;
    }

}
